/**
 * 
 */
package com.yufei.infoExtractor.io.http;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.cookie.Cookie;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;

import com.yufei.infoExtractor.util.IOUtils;

/**
 * @author zhaoyufei zhao-0244@qq.com
 *
 * created by zhaoyufei at 2012-7-21 上午10:30:18
 */
public class HttpClientHelper {

	/**
	 * @param args
	 * @throws Exception 
	 * @throws ClientProtocolException 
	 */
	public static void main(String[] args) throws ClientProtocolException, Exception {
		// TODO Auto-generated method stub
		String loginUrl="http://weibo.com/renzhiqiang#!/renzhiqiang?page=2&pre_page=1&end_id=3470105986310335&end_msign=-1";
		 DefaultHttpClient httpclient = new DefaultHttpClient();
	      
	            HttpGet httpget = new HttpGet(loginUrl);

	            HttpResponse response = httpclient.execute(httpget);
	            HttpEntity entity = response.getEntity();

	           // EntityUtils.consume(entity);

	            System.out.println("Initial set of cookies:");
	            List<Cookie> cookies = httpclient.getCookieStore().getCookies();
	            if (cookies.isEmpty()) {
	                System.out.println("None");
	            } else {
	                for (int i = 0; i < cookies.size(); i++) {
	                    System.out.println("- " + cookies.get(i).toString());
	                }
	            }
               System.out.print(IOUtils.translantByteStreamToString(IOUtils.translantStreamToByte(entity.getContent()), "utf-8"));


	}

}
